/**
 * 过往
 * @type {{aggregateWaters: number, summarySteams: number, aggregateGass: number, costPools: number, airCollectionss: number, aggregateCoolings: number, aggregateElectricitys: number, collectChart: number}}
 */

var energyDevId = {
    "collectChart": {
        id:10342,
        name:"碳排量"
    },//碳排
    "costPools": {
        id:10335,
        name:"成本量"
    },//成本
    "summarySteams": {
        id:10334,
        name:"蒸汽量"
    },//蒸汽
    "aggregateWaters": {
        id:10321,
        name:"用水量"
    },//用水
    "aggregateGass": {
        id:10314,
        name:"燃气量"
    },//燃气
    "aggregateElectricitys": {
        id:10307,
        name:"用电量"
    },//用电
    "airCollectionss": {
        id:10298,
        name:"空气量"
    },//空气
    "aggregateCoolings": {
        id:10290,
        name:"冷量量"
    }//冷量
};
var numberFormate = iot.getNumberFormat("0.00");
dev.action = function(resp,param){

    var spaceName = param.workSpaceName;
    var name = param.name;
    // 获取能源架构ID
    var workSpace = iot.getEnergySpaceId(spaceName,name);
    if (workSpace === -1){
        resp.setJsData("找不到数据");
        return;
    }

    var param= {
        id:energyDevId[name].id,
        time: param.time,
        selectType: param.selectType,
        workSpace:workSpace,
        workSpaceName: spaceName
    }

    if (spaceName === 'PV' || spaceName === 'pv'){
        iot.getPVDataToPast(JSON.stringify(param));
    }


    // 调用其他设备的 js 逻辑获取数据
    var jsResult = iot.bridgeOtherJsResult(JSON.stringify(param));
    var result = {
        dataYear : iot.list(),
        data : iot.list(),
        name : energyDevId[name].name
    }

    var timeDataList = getNearlyFourYears(param.time);


    var datas = jsResult.jsData.content;
    for(var time in timeDataList) {
        for (var i in datas) {
            if (timeDataList[time] === datas[i].year) {
                result.dataYear.add(datas[i].year);
                if (param.selectType === "single"){
                    result.data.add(decimalRetainRule(datas[i].useNum));
                }
                else if (name === "collectChart" || name === "costPools") {
                    result.data.add(decimalRetainRule(datas[i].useNum / 1000));
                }
                else {
                    result.data.add(decimalRetainRule(datas[i].useNum));
                }

            }
        }
    }

    resp.setJsData(result);
}